package com.itheima.health.service.impl;

import com.itheima.health.dao.SetmealOrderDao;
import com.itheima.health.pojo.PieChartData;
import com.itheima.health.service.SetmealOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
@Slf4j
public class SetmealOrderServiceImpl implements SetmealOrderService {

    @Autowired
    private SetmealOrderDao setmealOrderDao;

    @Override
    public PieChartData getSetmealReport() {
        List<PieChartData> setmealReport = setmealOrderDao.getSetmealReport();
        List<Map> maps = new ArrayList<>();

        for (PieChartData pieChartData : setmealReport) {

            Map map = new LinkedHashMap<>();
            map.put("value",pieChartData.getValue());
            map.put("name",pieChartData.getName());
            maps.add(map);
        }
        PieChartData pieChartData = new PieChartData();
        pieChartData.setSetmealCount(maps);

        return pieChartData;
    }
}
